class Solution:
	# @param gas, a list of integers
	# @param cost, a list of integers
	# @return an integer
	def canCompleteCircuit(self, gas, cost):
		div = [i-j for i,j in zip(gas, cost)]
		if sum(div) < 0:
			return -1
		i = j = div.index(max(div))
		ll = len(div)
		if ll == 2:
			return 0 if div[0] > div[1] else 1
		for x in xrange(ll-1):
			if div[(i-1)%ll] == div[(j+1)%ll]:
				if div[(i-1)%ll] > 0:
					i -= 1
				else:
					j += 1
			elif div[(i-1)%ll] > div[(j+1)%ll]:
				i -= 1
			else:
				j += 1
		return i % len(div)

if __name__ == '__main__':
	so = Solution()
	gas = [-1,2,-1]
	cost = [0 for i in gas]
	print so.canCompleteCircuit(gas, cost)